package com.yf1706.controller;



import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import org.apache.poi.util.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.yf1706.bean.CheckDetail;
import com.yf1706.service.inexcelService;

@Controller
@RequestMapping("excel")
public class ExcelInController {
	@Autowired
	private inexcelService in;
	//对数据上传做出处理		
	@RequestMapping(value = "uploadFileAction")
	@ResponseBody
    public List<CheckDetail> uploadFileAction(@RequestParam("uploadFile") MultipartFile uploadFile) {
        System.out.println(uploadFile);
		InputStream fis = null;
        OutputStream outputStream = null;
        try {
            fis = uploadFile.getInputStream();
            outputStream = new FileOutputStream("D:\\uploadfile\\"+uploadFile.getOriginalFilename());
            String filepath="D:\\uploadfile\\"+uploadFile.getOriginalFilename();
            File f1=new File(filepath);
            IOUtils.copy(fis,outputStream);
            return in.importData(f1);
        } catch (IOException e) {
            e.printStackTrace();
           return null;
        }finally {
            if(fis != null){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(outputStream != null){
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
